
package nav;

import fu.gk.GKPosition;
import fu.gps.GPSPosition;
import fu.gps.Spherical;



public class CoordinateTopologyObjectImpl implements ITopologyObject{

    private double x;
    private double y;
    
    private ITopologyObject parent;

    public CoordinateTopologyObjectImpl(ITopologyObject parent, double x, double y) {
        this.parent = parent;
    	this.x = x;
        this.y = y;
    }
    
    public CoordinateTopologyObjectImpl( double x, double y) {
    	this.x = x;
        this.y = y;
    }
    
    public void setParent(Object o){
    	this.parent =(ITopologyObject)o;
    }
    
    public Object read(String source) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String write() {
        String value = x + ", " + y;
        return value;
    }

    public double getX(){
        return x;
    }

    public double getY(){
        return y;
    }
    
    public void setX(double x){
        this.x=x;
    }

    public void setY(double y){
        this.y=y;
    }
    
    @Override
    public String toString(){
    	return "X: "+x+", Y: "+y;
    }
    
    public ITopologyObject getParent(){
    	return parent;
    }
    
    public boolean equals(CoordinateTopologyObjectImpl other){
    	if(this==other)
    		return true;
    	
    	if(Math.abs(distanceTo(other))>1)
    		return false;
    	else
    		return true;
    }
    
    public double distanceTo(CoordinateTopologyObjectImpl other){
    	if(other==this)
    		return 0;
    	
//    	GPSPosition p1 = new GPSPosition(this.x,this.y,0);
//    	GPSPosition p2 = new GPSPosition(other.x,other.y,0);
//    	GKPosition gkp1 = new GKPosition(p1);
//    	GKPosition gkp2 = new GKPosition(p2);
//    	return gkp2.distanceTo(gkp1);
//    	return Math.sqrt( (x-other.getX()) * (x-other.getX()) +(y-other.getY()) * (y-other.getY()) );
    	return Spherical.greatCircleMeters(y, x, other.getY(), other.getX());

    	
    }
    
    public double eucDistanceTo(CoordinateTopologyObjectImpl other){
    	if(other==this)
    		return 0;
    	
//    	GPSPosition p1 = new GPSPosition(this.x,this.y,0);
//    	GPSPosition p2 = new GPSPosition(other.x,other.y,0);
//    	GKPosition gkp1 = new GKPosition(p1);
//    	GKPosition gkp2 = new GKPosition(p2);
//    	return gkp2.distanceTo(gkp1);
    	return Math.sqrt( (x-other.getX()) * (x-other.getX()) +(y-other.getY()) * (y-other.getY()) );
//    	return Spherical.greatCircleMeters(x, y, other.getX(), other.getY());

    	
    }
}
